package com.fun.bean2json;


import com.alibaba.fastjson.JSON;
import net.sf.json.JSONObject;
import net.sf.json.xml.XMLSerializer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liyiruo
 * @Description
 * @Date 2021/6/23 下午4:33
 */
public class B2jTest {
    public static void main(String[] args) {
        Root root = new Root();
        Map map1 = new HashMap<String, String>();
        Map map2 = new HashMap<String, String>();
        List<String> stringList = new ArrayList<>();

        map1.put("map1key", "map1value");
        map1.put("map1key2", "map1value2");
        map2.put("map2key", "map2value");
        map2.put("map2key2", "map2value2");
        stringList.add("s1");
        stringList.add("s2");

        root.setAnInt(1111);
        root.setString("ssss");
        root.setMap1(map1);
        root.setMap2(map2);
        root.setStringList(stringList);
        String json = JSON.toJSONString(root);

        System.out.println("=========================");
        System.out.println(json);

        //如果是true这个对象加不进东西了
        JSONObject jsonObject2 = new JSONObject(true);
        JSONObject jsonObject = new JSONObject(false);
        jsonObject.put("root", root);

        String xml = new XMLSerializer().write(jsonObject);
        System.out.println(xml);
    }
}
